package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.mapper.MediaVideoMapper;
import com.example.demo.pojo.MediaVideo;
import com.example.demo.service.IMediaVideoService;
import com.example.demo.service.IUserPurchaseService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 视频元数据表 前端控制器
 * </p>
 *
 * @author gax
 * @since 2025-09-25
 */
@RestController
@RequestMapping("/video")
public class MediaVideoController {

    @Autowired
    private IMediaVideoService mediaVideoService;

    @Autowired
    private IUserPurchaseService userPurchaseService;

    // 返回所有视频列表元数据，用于前端渲染
    @GetMapping("list")
    public Result<List<MediaVideo>> list() {
        List<MediaVideo> list = mediaVideoService.list();
        return Result.ok(list);
    }

    // 获取播放地址：根据是否购买，返回 preview/full 的 URL 地址
    @GetMapping("/play/{id}")
    public Result<String> play(@PathVariable Long id, @RequestParam Long userId) {
        return Result.ok(mediaVideoService.getPlayableUrl(id, userId));
    }
}